/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DigaFoil;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.sql.Timestamp;
import java.util.Date;

/**
 *
 * @author ARMGARCES
 */
public class Tools {
    
    /**
     * Traduce el valor del JPasswordField a una cadena de caracteres
     * @param param1
     * @return
     */
    public static String charArrayToString(char[] param1){
        String result = "";
        for (int i = 0; i < param1.length; i++) {
            char c = param1[i];
            result += c;
        }
        return result;
    }
    /**
     * 
     * @return 
     */
    public static Date getDate(){
        Date expResult = new Date();
        java.sql.Timestamp timeStampDate = new Timestamp(expResult.getTime());        
        return timeStampDate;
    }
    /**
     * 
     * @return 
     */
    public static String getIpAddress(){
        String ip = "sin IP";
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException ex) {
        }
        return ip;
    }
    /**
     * 
     * @return 
     */
    public static String getMacAddress(){
        String mac = "sin MAC Address";
        try {
            InetAddress address = InetAddress.getLocalHost();
            NetworkInterface nwi = NetworkInterface.getByInetAddress(address);
            byte array[] = nwi.getHardwareAddress();            
            char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
            char[] hexChars = new char[array.length * 2];
            int v;
            for ( int j = 0; j < array.length; j++ ) {
                v = array[j] & 0xFF;
                hexChars[j * 2] = hexArray[v >>> 4];
                hexChars[j * 2 + 1] = hexArray[v & 0x0F];
            }
            mac = new String(hexChars);            
        } catch (Exception ex) {
        }
        return mac;
    }
}
